package edu.sctu.alex.projectPratice.forObject;
import java.util.Scanner;

/**
 * Created by user03 on 2015/5/26.
 */
public class Student {
     private String name;
     private int number;

    public String getSelectedDish() {
        return selectedDish;
    }

    public void setSelectedDish(String selectedDish) {
        this.selectedDish = selectedDish;
    }

    private String selectedDish;

    public String getSelectedWindow() {
        return selectedWindow;
    }

    public void setSelectedWindow(String selectedWindow) {
        this.selectedWindow = selectedWindow;
    }

    private String selectedWindow;
    public Student(){

    }
    public Student(String name,int number){
        this.name = name;
        this.number = number;
    }

    public CampusCard getCampusCard() {
        return campusCard;
    }

    public void setCampusCard(CampusCard campusCard) {
        this.campusCard = campusCard;
    }

    private CampusCard campusCard;

    Scanner in=new Scanner(System.in);


    public void haveBreakfast(){
        selectWindows();
        waitInLine();
        selectDish();
        swingCard();
        useCard();
        selectSeat();
        eatDish();
    }
    public void selectWindows(){


        Eatery eatery = new Eatery();
        String[] window  = eatery.setWindowName();

        System.out.println("请选择窗口： ");

        for (int i = 0; i <window.length ; i++) {
            System.out.println(window[i]);
        }
        String temp = in.next();

        if(temp.equals("窗口1") || temp.equals("窗口2")){

           setSelectedWindow(temp);


        }else {

            System.out.println("选择的窗口不存在，请重新选择！");
            System.exit(0);

        }
        System.out.println();

    }

    public void waitInLine(){
        Queue queue = new Queue();

        Queue[] queues = queue.setQueue();
        System.out.println("请输入你想排入的队列");
        System.out.println("可选择的队列:");
        for (int i = 0; i < queues.length ; i++) {
            System.out.println("队列："+ queues[i].getQueueNumber()+"  在等人数："+ queues[i].getWaittingPersonNum()+
            "   队列进度：" +queues[i].getQueueProgress());
        }
        int temp = in.nextInt();
    }



    public void selectDish(){
        Window window = new Window();


        System.out.println("今天想吃什么啊？");
        System.out.println("今天的菜点");
        System.out.println(getSelectedWindow());
        if(getSelectedWindow().equals("窗口1")) {
            for (int i = 0; i < window.getDishes1().length; i++) {
                System.out.println("菜名：" + window.getDishes1()[i].getDishName() + "   价格：" +
                        window.getDishes1()[i].getDishPrice());

            }
            setSelectedDish(in.next());
        }else if(getSelectedWindow().equals("窗口2")){

            for (int i = 0; i < window.getDishes2().length; i++) {
                System.out.println("菜名：" + window.getDishes2()[i].getDishName() + "   价格：" +
                        window.getDishes2()[i].getDishPrice());

            }

            setSelectedDish(in.next());

        }
        System.out.println("选择的菜："+getSelectedDish()+"  +米饭");

    }

    public void swingCard(){
        Student student = new Student();
        CampusCard card = new CampusCard();
        setCampusCard(card.listCampusCard());

        System.out.println("请输入你的学号，以便确认为本人：");
        int id = in.nextInt();
        if(id == getCampusCard().getNumber()){

            System.out.println("验证成功");
        }else{

            System.out.println("验证失败，无法购买");
            System.exit(0);
        }


    }

    public void useCard(){

        Window window = new Window();
        int balance = 0;

        System.out.println("卡上余额：" + getCampusCard().getMoney());
        if(getSelectedWindow().equals("窗口1")) {
            int price = 0;
            if (getSelectedDish().equals("回锅肉")) {

                price = window.getDishes1()[0].getDishPrice();

            } else if (getSelectedDish().equals("土豆丝")) {

                price = window.getDishes1()[1].getDishPrice();

            } else if (getSelectedDish().equals("干锅鸡")) {

                price = window.getDishes1()[2].getDishPrice();

            } else if(getSelectedDish().equals("鱼香茄子")){
                price = window.getDishes1()[3].getDishPrice();

            }

            balance = getCampusCard().getMoney() - price - window.getRicepiece();
            if (balance < 0) {
                System.out.println("木有法啊，买不起啊！！");
                System.out.println("重新选择吧！");
                System.exit(0);


            } else {
                System.out.println("买了" + getSelectedDish()+"  米饭" + "以后，卡里还有：" + balance);
            }
        }else if (getSelectedWindow().equals("窗口2")){
            int price = 0;
            if (getSelectedDish().equals("手抓牛肉")) {

                price = window.getDishes1()[0].getDishPrice();

            } else if (getSelectedDish().equals("炝白菜")) {

                price = window.getDishes1()[1].getDishPrice();

            } else if (getSelectedDish().equals("家常豆腐")) {

                price = window.getDishes1()[2].getDishPrice();

            } else if(getSelectedDish().equals("水煮肉片")){
                price = window.getDishes1()[3].getDishPrice();

            }

            balance = getCampusCard().getMoney() - price - window.getRicepiece();
            if (balance < 0) {
                System.out.println("木有法啊，买不起啊！！");
                System.out.println("重新选择吧！");
                System.exit(0);


            } else {
                System.out.println("买了" + getSelectedDish() + "以后，卡里还有：" + balance);
            }
        }
        getCampusCard().setMoney(balance);
    }

    public void selectSeat(){
        Eatery eatery  = new Eatery();
        String seat=null;
        do{
            eatery.listSeat();
            System.out.println("是否入座？是-入座，否-重新寻找位置");
            seat = in.next();


        }while (seat.equals("否"));
        if(seat.equals("是")){
            System.out.println("成功入座");

        }else {
            System.out.println("选择错误！！");
            System.exit(0);

        }

        
    }

    public  void eatDish(){

        System.out.println("姓名："+name+" 学号:"+getCampusCard().getNumber());
        System.out.println("你选择的菜品是："+getSelectedDish()+"  +米饭");
        System.out.println("你的卡上余额："+getCampusCard().getMoney());
        System.out.println("成功入座");
    }



}
